﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;



public class BattleComponent<ComponentData> : MonoBehaviour where ComponentData : class {

    public static List<ComponentData> ComponentDataList = new List<ComponentData>();
    public static List<bool> ComponentDataEnableList = new List<bool>();

    public static void Assign(ComponentData data)
    {
        
        if (!ComponentDataList.Contains(data))
        {
            ComponentDataList.Add(data);
            ComponentDataEnableList.Add(true);
        }
    }

    public static void Unassign(ComponentData data)
    {
        int id= ComponentDataList.FindIndex(t => t == data);
        if(id!=-1) ComponentDataEnableList[id] = false;
    }

    public static void CleanUpComponent()
    {
        int i = 0;
        while(i< ComponentDataList.Count)
        {
            if(ComponentDataEnableList[i])
            {
                i++;
            }
            else
            {
                ComponentDataList.RemoveAt(i);
                ComponentDataEnableList.RemoveAt(i);
            }
        }
    }
}





